package com.qf.action;

import com.qf.dto.DqGroundsDTO;
import com.qf.dto.PageDTO;
import com.qf.dto.ResultDTO;
import com.qf.service.DqGroundsService;
import com.qf.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.text.ParseException;
import java.util.Date;

/**
 * //                       .::::.
 * //                     .::::::::.
 * //                    :::::::::::  come on
 * //                 ..:::::::::::'
 * //              '::::::::::::'
 * //                .::::::::::
 * //           '::::::::::::::..
 * //                ..::::::::::::.
 * //              ``::::::::::::::::
 * //               ::::``:::::::::'        .:::.
 * //              ::::'   ':::::'       .::::::::.
 * //            .::::'      ::::     .:::::::'::::.
 * //           .:::'       :::::  .:::::::::' ':::::.
 * //          .::'        :::::.:::::::::'      ':::::.
 * //         .::'         ::::::::::::::'         ``::::.
 * //     ...:::           ::::::::::::'              ``::.
 * //    ```` ':.          ':::::::::'                  ::::..
 * //                       '.:::::'                    ':'````..
 * //
 *
 * @author:小川
 * @date: 2018/11/24 16:58
 */
@Controller
public class DqGroundsAction {
    @Autowired
    private DqGroundsService dqGroundsService;
    @RequestMapping("/item/groundlist")
    @ResponseBody
    public PageDTO showGrounds(int page,int rows){
        PageDTO pageDTO = dqGroundsService.findAll(page, rows);
        return pageDTO;
    }
    @RequestMapping("/item/groundedit")
    @ResponseBody
    public ResultDTO update(HttpServletRequest request) throws ParseException {
        String id = request.getParameter("id");
        String entryid = request.getParameter("entryid");
        String name = request.getParameter("name");
        String description = request.getParameter("description");
        DqGroundsDTO dqGroundsDTO=new DqGroundsDTO();
        dqGroundsDTO.setId(Integer.parseInt(id));
        dqGroundsDTO.setUpdatedAt(DateUtils.dateToString(new Date()));
        dqGroundsDTO.setDescription(description);
        dqGroundsDTO.setName(name);
        int i = dqGroundsService.update(dqGroundsDTO);


        return ResultDTO.ok();
    }
    @RequestMapping("/item/grounddelete")
    @ResponseBody
    public ResultDTO delete(int[] ids){
        for (int id : ids) {
            dqGroundsService.delete(id);
        }
        return ResultDTO.ok();
    }
}
